package com.qihoo.finance.fake.module.msf.facade;

import com.github.pagehelper.PageInfo;
import com.qihoo.finance.fake.module.msf.dao.SystemGeneralDao;
import com.qihoo.finance.fake.module.msf.entity.generate.SystemDictEntity;
import com.qihoo.finance.msf.api.domain.Response;
import com.qihoo.finance.msf.api.sys.domain.SystemDictDomain;
import com.qihoo.finance.msf.api.sys.facade.SystemDictFacade;
import com.qihoo.finance.msf.api.sys.request.SystemDictRequest;
import com.qihoo.finance.msf.core.utils.BeanUtils2;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by yuyi
 */

@Service("systemDictFacadeImpl")
public class SystemDictFacadeImpl implements SystemDictFacade {

    private static final Logger logger = LogManager.getLogger(SystemParamFacadeImpl.class);

    @Resource
    private SystemGeneralDao systemGeneralDao;

    @Override
    public Response<PageInfo> selectSysDictListByCondation(SystemDictRequest request) {
        throw new UnsupportedOperationException("unSupport");
    }

    @Override
    public Response<SystemDictDomain> selectByPrimaryKey(int id) {
        throw new UnsupportedOperationException("unSupport");
    }

    @Override
    public Response<Integer> updateAndValidateRoles(SystemDictDomain domain, List<String> roles) {
        throw new UnsupportedOperationException("unSupport");
    }

    @Override
    public Response<Integer> deleteAndValidateRoles(SystemDictDomain domain, List<String> roles) {
        throw new UnsupportedOperationException("unSupport");
    }

    @Override
    public Response<Integer> insert(SystemDictDomain domain) {
        throw new UnsupportedOperationException("unSupport");
    }

    @Override
    public Response<List<SystemDictDomain>> queryValidOfModules(List<String> modules) {
        if (org.springframework.util.CollectionUtils.isEmpty(modules)) {
            logger.warn("modules is empty. modules={}", modules);
            return new Response().fail();
        }
        try {
            List<SystemDictEntity> systemDictEntities = systemGeneralDao.queryValidOfModules(modules);
            List<SystemDictDomain> systemDictDomains = BeanUtils2.copyBeanList(SystemDictDomain.class, systemDictEntities);
            return new Response().success(systemDictDomains);
        }catch(Exception e){
            logger.error("queryValidOfModules error. modules={}", modules, e);
            return new Response().fail();
        }
    }


}
